package com.warehouse.module.business.controller.admin.cargofile;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.warehouse.framework.common.pojo.PageParam;
import com.warehouse.framework.common.pojo.PageResult;
import com.warehouse.framework.common.pojo.CommonResult;
import com.warehouse.framework.common.util.object.BeanUtils;
import static com.warehouse.framework.common.pojo.CommonResult.success;

import com.warehouse.framework.excel.core.util.ExcelUtils;

import com.warehouse.framework.apilog.core.annotation.ApiAccessLog;
import static com.warehouse.framework.apilog.core.enums.OperateTypeEnum.*;

import com.warehouse.module.business.controller.admin.cargofile.vo.*;
import com.warehouse.module.business.dal.dataobject.cargofile.CargoFileDO;
import com.warehouse.module.business.service.cargofile.CargoFileService;

@Tag(name = "管理后台 - 货物资料附件")
@RestController
@RequestMapping("/warehouse-business/cargo-file")
@Validated
public class CargoFileController {

    @Resource
    private CargoFileService cargoFileService;

    @PostMapping("/create")
    @Operation(summary = "创建货物资料附件")
    @PreAuthorize("@ss.hasPermission('warehouse-business:cargo-file:create')")
    public CommonResult<Long> createCargoFile(@Valid @RequestBody CargoFileSaveReqVO createReqVO) {
        return success(cargoFileService.createCargoFile(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新货物资料附件")
    @PreAuthorize("@ss.hasPermission('warehouse-business:cargo-file:update')")
    public CommonResult<Boolean> updateCargoFile(@Valid @RequestBody CargoFileSaveReqVO updateReqVO) {
        cargoFileService.updateCargoFile(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除货物资料附件")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('warehouse-business:cargo-file:delete')")
    public CommonResult<Boolean> deleteCargoFile(@RequestParam("id") Long id) {
        cargoFileService.deleteCargoFile(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得货物资料附件")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('warehouse-business:cargo-file:query')")
    public CommonResult<CargoFileRespVO> getCargoFile(@RequestParam("id") Long id) {
        CargoFileDO cargoFile = cargoFileService.getCargoFile(id);
        return success(BeanUtils.toBean(cargoFile, CargoFileRespVO.class));
    }
//
//    @GetMapping("/page")
//    @Operation(summary = "获得货物资料附件分页")
//    @PreAuthorize("@ss.hasPermission('warehouse-business:cargo-file:query')")
//    public CommonResult<PageResult<CargoFileRespVO>> getCargoFilePage(@Valid CargoFilePageReqVO pageReqVO) {
//        PageResult<CargoFileDO> pageResult = cargoFileService.getCargoFilePage(pageReqVO);
//        return success(BeanUtils.toBean(pageResult, CargoFileRespVO.class));
//    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出货物资料附件 Excel")
//    @PreAuthorize("@ss.hasPermission('warehouse-business:cargo-file:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportCargoFileExcel(@Valid CargoFilePageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<CargoFileDO> list = cargoFileService.getCargoFilePage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "货物资料附件.xls", "数据", CargoFileRespVO.class,
//                        BeanUtils.toBean(list, CargoFileRespVO.class));
//    }

}